package com.briup.cms.config;

import com.briup.cms.web.interceptor.JwtInterceptor ;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 添加jwt拦截器,并指定拦截路径
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())
                .addPathPatterns("/user/**","/role/**","/comment/**","/category/**","/article/**")
                .excludePathPatterns("/","swagger-ui.html","/user/login","/user/saveUser",
                                    "/comment/findCommentAll","/comment/findAllByArticleId",
                                    "/category/findCategoryByUsername","/category/findCategoryAll","/category/findAllSortbyno",
                                    "/article/findArticleAll","/article/findAllCommentsByArticleId");
    }

    /**
     * jwt拦截器
     */
    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }
}
